package com.guaju.yueshangLife.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.databinding.DataBindingUtil;
import android.databinding.ViewDataBinding;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.FrameLayout;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.databinding.ItemRefundLineBinding;
import com.guaju.yueshangLife.utils.DateUtils;

public class RefundLineItem extends FrameLayout {

    private LayoutInflater layoutInflater;
    private ItemRefundLineBinding binding;

    public RefundLineItem(Context context) {
        super(context);
        init();
    }

    public RefundLineItem(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.item_refund_line);
        String title = ta.getString(R.styleable.item_refund_line_status_title);
        binding.refundStatus.setText(title);
        boolean leftVisible = ta.getBoolean(R.styleable.item_refund_line_leftvisible, true);
        boolean leftenable = ta.getBoolean(R.styleable.item_refund_line_leftenable, false);
        boolean rightVisible = ta.getBoolean(R.styleable.item_refund_line_rightvisible, true);
        boolean rightenable = ta.getBoolean(R.styleable.item_refund_line_rightenable, false);
        if (leftVisible) {
            binding.leftLine.setVisibility(VISIBLE);
        } else {
            binding.leftLine.setVisibility(INVISIBLE);
        }
        if (rightVisible) {
            binding.rightLine.setVisibility(VISIBLE);
        } else {
            binding.rightLine.setVisibility(INVISIBLE);
        }
        if (!leftenable) {
            setLeftEnable(false);
        } else {
            setLeftEnable(true);
        }
        if (!rightenable) {
            setRightEnable(false);
        } else {
            setRightEnable(true);
        }


    }

    private void init() {
        layoutInflater = LayoutInflater.from(getContext());
        binding = DataBindingUtil.inflate(layoutInflater, R.layout.item_refund_line, null, false);
        addView(binding.getRoot());
    }

    public void setTime(String time) {
        binding.refundTime.setText(time);
    }

    public void setTime(int time) {
        DateUtils.getFormatedTime(time + "");
    }

    public void setRightEnable(boolean enable) {
        if (enable) {
            binding.rightLine.setBackgroundColor(getResources().getColor(R.color.green));
        } else {
            binding.rightLine.setBackgroundColor(getResources().getColor(R.color.c_gray2));
        }
    }

    public void setLeftEnable(boolean enable) {
        if (enable) {
            binding.leftLine.setBackgroundColor(getResources().getColor(R.color.green));
        } else {
            binding.leftLine.setBackgroundColor(getResources().getColor(R.color.c_gray2));

        }
    }

    public void setDotLight(boolean enable) {
        if (enable) {
            binding.centerPoint.setBackgroundColor(getResources().getColor(R.color.green));
        } else {
            binding.centerPoint.setBackgroundColor(getResources().getColor(R.color.c_gray2));
        }
    }


}
